<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.js"></script>
    <script type="text/javascript" src="../js/respond.min.js"></script>
    <![endif]-->
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../css/H-ui.css" />
    <link rel="stylesheet" type="text/css" href="../css/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../css/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />

    <title>角色管理</title>
</head>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i>
    首页 <span class="c-gray en">&gt;</span>
    管理员管理 <span class="c-gray en">&gt;</span>
    角色管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
    <i class="Hui-iconfont">&#xe68f;</i>
</a>
</nav>
<div class="page-container">
    <input type="hidden" id="roleId" data-roleid= ""/>
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius" href="javascript:;" onclick="admin_role_add('添加角色','toAddRole','800')"><i class="Hui-iconfont">&#xe600;</i> 添加角色</a>
        </span>
        <span class="r">共有数据：<strong class="total"> </strong> 条</span>
    </div>
    <div>
        <form action="" id="search" class="hidden">
            <input type="text" value="" name="userId"/>
        </form>
    </div>
    <table class="table table-border table-bordered table-hover table-bg">
        <thead>
        <tr>
            <th scope="col" colspan="4">角色管理</th>
        </tr>
        <tr class="text-c">
            <th width="150">角色名</th>
            <th width="150">员工</th>
            <th width="150">创建时间</th>
            <th width="150">操作</th>
        </tr>
        </thead>
        <tbody class="tableCon">
        </tbody>
    </table>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="../js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../js/H-ui.js"></script>
<script type="text/javascript" src="../js/H-ui.min.js"></script>
<script type="text/javascript" src="../js/postJson.js"></script>
<script type="text/javascript" src="../js/root.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/js/jquery.contextmenu.r2.js"></script>
<script type="text/javascript">

        function getData() {
            var dataCollect=$('#search').serialize();
            var dataCollects = dataCollect.replace(/\+/g," ");
            dataCollects= decodeURIComponent(dataCollects,true);//防止中文乱码
            var jsondata=strJSON.formToJson(dataCollects);//转化为json
            var url = "/sysRole/userRolesList";
            $.ajax({
                url:url,
                contentType:"application/json",
                data:jsondata,
                type:"post",
                async:false,
                dataType:'json',
                success:function(msg){
                    if (msg.success) {
                        var htmlString = '';
                        $(".total").text(msg.data.length);
                        $.each(msg.data,function(i,n){
                            htmlString += '<tr class="text-c" roleid="'+ n.id+'">'
                            htmlString += '<td>'+ n.name+'</td>'
                            htmlString += '<td>'
                            htmlString += '<a class="btn btn-danger radius" onclick="user_query('+"\'角色查看\'"+','+"\'toRoleQuery\'"+','+ 800+','+ 600+','+ n.id+')">查看</a>'
                            htmlString += '</td>'
                            htmlString += '<td>'+ TimeHours(n.createTime) +'</td>'
                            htmlString += '<td class="f-14">'
                            htmlString += '<a title="编辑" raleId = "'+ n.id+'" href="javascript:;" onclick="admin_role_edit('+"\'角色修改\'"+','+"\'toUpdateRole\'"+','+ n.id+')"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_role_del(this,'+n.id+')" class="ml-5"><i class="Hui-iconfont">&#xe6e2;</i></a>'
                            htmlString += '</td>'
                            htmlString += '</tr>'
                        })
                        $(".tableCon ").empty().append(htmlString);
                    } else {
                        var error = msg.errorMessage;
                        parent.layer.msg(error, {icon: 2, time: 3000});
                    }
                },
                error:function(XMLHttpRequest,textStatus,errorThrown){
                    // console.log(XMLHttpRequest.readyState)
                    // console.log(textStatus)
                    // console.log(errorThrown)
                    // console.log(XMLHttpRequest)
                }
            });
        }
        getData();


        /*管理员-角色-添加*/
        function admin_role_add(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*管理员-角色-编辑*/
        function admin_role_edit(title,url,id,w,h){
            $("#roleId").attr("data-roleId",id)
            layer_show(title,url,w,h);
        }
        /*管理员-查询*/
        function user_query(title,url,w,h,id){
            $("#roleId").attr("data-roleId",id)
            layer_show(title,url,w,h);
        }
        function admin_role_del(obj,roleId){
            var dataCollect="id="+roleId;
            dataCollect= decodeURIComponent(dataCollect,true);//防止中文乱码
            var jsondata=strJSON.formToJson(dataCollect);//转化为json
            var url = "/sysRole/deleteRole";
             layer.confirm('角色删除须谨慎，确认要删除吗？',function(index){
                 $.ajax({
                     type: 'POST',
                     url: url,
                     contentType:"application/json",
                     data:jsondata,
                     dataType: 'json',
                     success: function(data) {
                         if (data.success == true) {
                             $(obj).parents("tr").remove();
                             layer.msg('已删除!', {icon: 1, time: 3000});
                         }else{
                             parent.layer.msg(data.errorMessage,{icon:2,time:5000});
                         }
                     },
                     error:function(XMLHttpRequest,textStatus,errorThrown){
                         var XmlStatus = XMLHttpRequest.status
//                         console.log(XMLHttpRequest.status)
                         if(XmlStatus==401){
                             alert(XmlError.error401)
                             parent.window.location.href = "../login.html"
                         }
                         if(XmlStatus==403){
                             alert(XmlError.error403)
                         }
                     }
                 });
             });
         }

</script>

</body>
</html>